-- variable
-- 	global
-- 	local
-- 	non-local

names = {"peter", "paul", "mary"}
grades = {mary = 10, paul = 7, peter = 8}

function sortByGrade (names, grades)
	table.sort(names, function (n1, n2)
		return grades[n1] > grades[n2] 	-- we use a external variable in a anonymous function
	end) 															-- now grades is a non-local variable for this anonymous func
end

function newCounter ()
	local count = 0
	return function () 	-- anonymous function
		count = count + 1
		return count
	end
end

c1 = newCounter() 	-- a closure
print(c1()) 	--> 1
print(c1()) 	--> 2

c2 = newCounter() 	-- a different closure
print(c2()) 	--> 1
print(c1()) 	--> 3
print(c2()) 	--> 2
